package com.start.oss;

import io.minio.MinioClient;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "start.upload.storages.minio")
public class StartOssMinioStorageConfig {

    private String endpoint;

    private String url;

    private String accessKey;

    private String secretKey;

    private String bucketName;

    /**
     * 注入minio 客户端
     *
     * @return
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }

    public String getMinioOssRootUrl() {
        if (StringUtils.isNotBlank(url)) {
            return url;
        }
        return endpoint;
    }


}
